package com.yonyou.brigade.third_parties.didi.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yonyou.brigade.basic_init.enums.ChannelEnum;
import com.yonyou.brigade.basic_init.model.BriChannel;
import com.yonyou.brigade.basic_init.service.IBaseDocService;
import com.yonyou.brigade.basic_init.service.IBriChannelService;
import com.yonyou.brigade.basic_init.service.IDeveloperService;
import com.yonyou.brigade.basic_init.service.IUserCenterService;
import com.yonyou.brigade.third_parties.didi.dao.DiDiUserMapper;
import com.yonyou.brigade.third_parties.didi.model.DiDiConfig;
import com.yonyou.brigade.third_parties.didi.model.DiDiUser;
import com.yonyou.brigade.third_parties.didi.service.IDiDiUserService;
import com.yonyou.brigade.third_parties.didi.util.DiDiConstants;
import com.yonyou.brigade.third_parties.didi.util.DiDiRMIUtils;
import com.yonyou.brigade.third_parties.didi.util.DiDiResultUtil;
import com.yonyou.brigade.third_parties.didi.util.DiDiUtil;
import com.yonyou.brigade.util.mail.MailSenderUtil;
import com.yonyou.ybzboot.starter.common.exception.CustomException;
import com.yonyou.ybzboot.starter.common.util.StringUtil;
import com.yonyou.ybzboot.uc.dto.UcUserDto;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.*;
import java.util.regex.Pattern;

/**
 * 滴滴用户 服务
 *
 * @author jiangzhf
 */
@Service
public class DiDiUserServiceImpl extends ServiceImpl<DiDiUserMapper, DiDiUser> implements IDiDiUserService {

    @Autowired
    @Qualifier("userCenterServiceImpl")
    private IUserCenterService iUserCenterService;

    @Autowired
    @Qualifier("baseDocServiceImpl")
    private IBaseDocService baseDocService;

    @Autowired
    private DiDiUserMapper didiUserMapper;

    @Autowired
    private DiDiRMIUtils diDiRMIUtils;

    @Autowired
    @Qualifier("briChannelServiceImpl")
    private IBriChannelService briChannelService;

    @Autowired
    private IDeveloperService developerService;

    @Value("${didi.h5url}")
    private String didiH5Url;
    /**
     * 正则预编译
     */
    private static final Pattern PHONE_PATTERN = Pattern.compile("^[1][3,4,5,7,8,9][0-9]{9}$");
    private static final Pattern NAME_PATTERN1 = Pattern.compile("^[\u4e00-\u9fa5a-zA-Z0-9]+$");
    private static final Pattern NAME_PATTERN2 = Pattern.compile("^[\u4e00-\u9fa5]+(·[\u4e00-\u9fa5]+)*$");

    private final Logger logger = LoggerFactory.getLogger(DiDiUserServiceImpl.class);

    /**
     * 同步用户信息
     *
     * @param tenant 租户ID
     * @return <code>{"code":"0","message":"用户同步成功！"+erroInfo.toString()}</code>
     */
    @Override
    public Map<String, Object> saveUsers(String tenant) {
        Map<String, Object> memberResultMap = new HashMap<>();
        List<UcUserDto> userList = iUserCenterService.getUcUsersByTenantId(tenant);
        BriChannel briChannel = briChannelService.getEnableChannelByOpenType(tenant, ChannelEnum.DIDI.getName(), 1);
        DiDiConfig diDiConfig = JSON.parseObject(briChannel.getConfig(), DiDiConfig.class);
//        DiDiConfig diDiConfig = (DiDiConfig) briChannelService.getChannelConfig(tenant, ChannelEnum.DIDI.getName(), "", new DiDiConfig());


        String phoneError = "";
        String nameError = "";
        //标识是否已经有数据同步成功
        boolean hasSuccess = false;
        StringBuilder errorInfo = new StringBuilder();
        if (BriChannel.SYNCUSER == briChannel.getSyncUser()) {
            Map needAsyUsersResult = getNeedAsyDiDiUsers(tenant, userList);
            List<DiDiUser> needSyncUsers = (List<DiDiUser>) needAsyUsersResult.get("data");
            phoneError = needAsyUsersResult.get("phoneError").toString();
            nameError = needAsyUsersResult.get("nameError").toString();
            if (needSyncUsers != null && needSyncUsers.size() > 0) {
                for (DiDiUser diDiUser : needSyncUsers) {
                    try {
                        addSingleUser(tenant, diDiUser);
                    } catch (Exception e) {
                        errorInfo.append(e.getMessage());
                        errorInfo.append(" ");
                    }
                }

            /*List<List<DiDiUser>> lists = ListUtils.partition(needSyncUsers, 500);
            for (List<DiDiUser> list : lists) {
                Map<String, Object> membParamsMap = getMemberData(diDiConfig, list);
                String resultJsonStr = diDiRMIUtils.executeRMIRequest(DiDiConstants.METHOD_POST_USERADD, membParamsMap, "POST");
                JSONObject companyResult = new JSONObject(resultJsonStr);
                if ("0".equals(companyResult.opt("errno").toString())) {
                    JSONArray array = companyResult.optJSONArray(DiDiConstants.DATA);
                    if (array != null && array.length() > 0) {
                        for (int i = 0; i < array.length(); i++) {
                            DiDiUser diDiUser = new DiDiUser();
                            String phone = array.getJSONObject(i).get("phone").toString();
                            diDiUser.setDdMemberId(array.getJSONObject(i).get("id").toString());
                            diDiUser.setPhone(phone);
                            List<DiDiUser> temps = list.stream().filter(s -> s.getPhone().equals(phone)).collect(Collectors.toList());
                            if (temps != null && temps.size() > 0) {
                                diDiUser.setEmail(temps.get(0).getEmail());
                                diDiUser.setEmployeeNumber(temps.get(0).getEmployeeNumber());
                                diDiUser.setOrg(temps.get(0).getOrg());
                                diDiUser.setTenant(tenant);
                                diDiUser.setRealname(temps.get(0).getRealname());
                                diDiUser.setUserId(temps.get(0).getUserId());
                            }
                            didiUserMapper.insert(diDiUser);
                        }
                        hasSuccess = true;
                    }
                    if (!"SUCCESS".equalsIgnoreCase(companyResult.optString("errmsg"))) {
                        errorInfo.append(companyResult.optString("errmsg") == null ? " " : companyResult.optString("errmsg"));
                        errorInfo.append(" ");
                    }
                } else {
                    errorInfo.append(companyResult.optString("errmsg") == null ? " " : companyResult.optString("errmsg"));
                    errorInfo.append(" ");
                }
            }*/
            }
        }
        if (!StringUtil.isEmpty(phoneError)) {
            errorInfo.append("手机号校验错误：");
            errorInfo.append(phoneError.substring(1));
            errorInfo.append(" ");
        }
        if (!StringUtil.isEmpty(nameError)) {
            errorInfo.append("用户名不符合滴滴规范：");
            errorInfo.append(nameError.substring(1));
        }
        if (hasSuccess) {
            memberResultMap.put("code", "0");
            if (errorInfo.length() > 0) {
                logger.error("部分用户同步成功！" + errorInfo);
                memberResultMap.put("message", "部分用户同步成功！" + errorInfo);
            } else {
                memberResultMap.put("message", "用户同步成功！" + errorInfo);
            }
        } else {
            memberResultMap.put("code", "-1");
            memberResultMap.put("message", "同步滴滴用户失败！" + errorInfo);
            logger.error("同步滴滴用户失败！" + errorInfo);
        }
        return memberResultMap;
    }

    /**
     * 滴滴开通时同步用户信息
     *
     * @param tenant 租户ID
     * @param phone  管理员手机号
     */
    @Override
    @Async
    public void syncUsers4Open(String tenant, String phone) {
        UcUserDto ucUserDto = iUserCenterService.getCompleteUcUserDtoByPhone(phone, tenant);

        StringBuilder syncResult = new StringBuilder();
        syncResult.append("滴滴自助开通提醒：\n租户 ").append(tenant).append(" ，管理员手机号 ").append(phone).append("。\n开通过程信息：");
        if (ucUserDto == null) {
            syncResult.append("用户中心连接失败。");
        } else {
            Map<String, Object> batchSaveMessage = saveUsers(tenant);
            syncResult.append(batchSaveMessage.toString());
        }
        logger.info(syncResult.toString());

        MailSenderUtil.sendCommonMail(developerService.listEmailByType("YY"), "滴滴开通", syncResult.toString());
    }

    /**
     * 向滴滴同步用户
     *
     * @param tenant   租户ID
     * @param diDiUser 滴滴用户
     */
    @Override
    public void addSingleUser(String tenant, DiDiUser diDiUser) {
        DiDiConfig diDiConfig = (DiDiConfig) briChannelService.getChannelConfig(tenant, ChannelEnum.DIDI.getName(), "", new DiDiConfig());
        Map<String, Object> memberData = getSingleMemberData(diDiConfig, diDiUser);
        String resultJsonStr = diDiRMIUtils.executeRMIRequest(DiDiConstants.METHOD_POST_USER_SINGLE_ADD, memberData, "POST");
        JSONObject resultJson = new JSONObject(resultJsonStr);
        if ("0".equals(resultJson.optString("errno"))) {
            JSONObject data = resultJson.optJSONObject(DiDiConstants.DATA);
            if (data != null) {
                diDiUser.setDdMemberId(data.optString("id"));
                didiUserMapper.insert(diDiUser);
            }
        } else if ("50202".equals(resultJson.optString("errno"))) {
            // 50202 添加员工失败（员工已存在）
            com.alibaba.fastjson.JSONObject userJson = this.querySingleUser(tenant, diDiUser.getPhone());
            if (userJson != null) {
                diDiUser.setDdMemberId(userJson.getString("id"));
                didiUserMapper.insert(diDiUser);
            }
        } else {
            throw new CustomException("用户同步异常,"+ "" + resultJson.getString("errmsg"));
        }
    }

    @Override
    public com.alibaba.fastjson.JSONObject querySingleUser(String tenant, String phone) {
        DiDiConfig diDiConfig = (DiDiConfig) briChannelService.getChannelConfig(tenant, ChannelEnum.DIDI.getName(), "", new DiDiConfig());
        Map<String, Object> queryMemberParam = getQueryMemberParam(diDiConfig, phone);
        String resultJsonStr = diDiRMIUtils.executeRMIRequest(DiDiConstants.METHOD_GET_USER_QUERY, queryMemberParam, RequestMethod.GET.name());

        com.alibaba.fastjson.JSONObject result = (com.alibaba.fastjson.JSONObject) DiDiResultUtil.handleResult(resultJsonStr, com.alibaba.fastjson.JSONObject.class);
        com.alibaba.fastjson.JSONArray records = result.getJSONArray("records");

        return records.size() > 0 ? records.getJSONObject(0) : null;
    }

    /**
     * 查询参数组装
     *
     * @param diDiConfig 配置信息
     * @param phone      手机号
     * @return
     */
    private Map<String, Object> getQueryMemberParam(DiDiConfig diDiConfig, String phone) {
        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put(DiDiConstants.KEY_CLIENT_ID, diDiConfig.getClientId());
        paramsMap.put(DiDiConstants.KEY_ACCESS_TOKEN, diDiRMIUtils.getToken(diDiConfig));
        paramsMap.put(DiDiConstants.KEY_TIMESTAMP, System.currentTimeMillis());
        paramsMap.put(DiDiConstants.KEY_COMPANY_ID, diDiConfig.getCompanyId());
        paramsMap.put(DiDiConstants.KEY_OFFSET, 0);
        paramsMap.put("length", 100);
        paramsMap.put(DiDiConstants.KEY_PHONE, phone);

        Map<String, Object> memberQueryParamsMap = diDiRMIUtils.keySort(paramsMap, diDiConfig);
        String sign = diDiRMIUtils.concatRequestParamsAndMd5Encode(memberQueryParamsMap);
        memberQueryParamsMap.put(DiDiConstants.KEY_SIGN, sign);
        paramsMap.put(DiDiConstants.KEY_SIGN, sign);
        return paramsMap;
    }


    /**
     * 修改用户
     *
     * @param tenant   租户ID
     * @param diDiUser 滴滴用户
     */
    @Override
    public void updateUser(String tenant, DiDiUser diDiUser) {
        DiDiConfig diDiConfig = (DiDiConfig) briChannelService.getChannelConfig(tenant, ChannelEnum.DIDI.getName(), "", new DiDiConfig());
        Map<String, Object> updateMemberData = getUpdateMemberData(diDiConfig, diDiUser);

        String resultJsonStr = diDiRMIUtils.executeRMIRequest(DiDiConstants.METHOD_POST_USER_UPDATE, updateMemberData, "POST");
        JSONObject resultJson = new JSONObject(resultJsonStr);

        if (!"0".equals(resultJson.optString("errno"))) {
            logger.error("滴滴：修改用户信息失败，错误信息：" + resultJsonStr);
            List<String> mailList = developerService.listEmailByType("YY");
            MailSenderUtil.sendCommonMail(mailList, "滴滴：修改用户信息失败", "用户信息：" + diDiUser.toString() + "\n错误信息：" + resultJsonStr);
        }
    }

    /**
     * 删除用户
     *
     * @param tenant       租户ID
     * @param didiUserList 手机号
     */
    @Override
    public void deleteUsers(String tenant, List<DiDiUser> didiUserList) {
        DiDiConfig diDiConfig = (DiDiConfig) briChannelService.getChannelConfig(tenant, ChannelEnum.DIDI.getName(), "", new DiDiConfig());

        StringBuilder errorStr = new StringBuilder();
        List<List<DiDiUser>> lists = ListUtils.partition(didiUserList, 100);
        for (List<DiDiUser> list : lists) {
            Map<String, Object> deleteMemberData = getDeleteMemberData(diDiConfig, list);
            String resultJsonStr = diDiRMIUtils.executeRMIRequest(DiDiConstants.METHOD_POST_USER_DELETE, deleteMemberData, "POST");
            String memberIds = (String) deleteMemberData.get("member_id");
            logger.error("滴滴用户删除，用户ID：{}", memberIds);

            JSONObject resultJson = new JSONObject(resultJsonStr);
            if (!"SUCCESS".equalsIgnoreCase(resultJson.optString("errmsg"))) {
                errorStr.append(memberIds).append(resultJsonStr).append("\n");
            }
            Wrapper<DiDiUser> wrapper = new EntityWrapper<>();
            wrapper.in(DiDiUser.DD_MEMBER_ID, memberIds.split("_"));
            DiDiUser updateValid = new DiDiUser();
            updateValid.setValid(0);
            this.update(updateValid, wrapper);
        }

        if (StringUtils.isNotEmpty(errorStr.toString())) {
            String msg = "滴滴用户删除错误，错误内容：" + errorStr.toString();
            logger.error(msg);
            throw new CustomException(msg);
        }
    }

    /**
     * 获取滴滴企业版H5 URL并且会触发单个用户的同步及变更
     *
     * @param tenant 租户ID
     * @param org    租户PK
     * @param phone  用户手机号
     * @return String 滴滴企业版H5地址 无单点
     */
    @Override
    public String getH5Url(String tenant, String org, String phone) {
        BriChannel briChannel = briChannelService.getEnableChannelByOpenType(tenant, ChannelEnum.DIDI.getName(), 1);
        if (briChannel != null && BriChannel.SYNCUSER == briChannel.getSyncUser()) {
            // 查询开通信息，未开通返回null
            DiDiConfig diDiConfig = JSON.parseObject(briChannel.getConfig(), DiDiConfig.class);
//            DiDiConfig diDiConfig = (DiDiConfig) briChannelService.getChannelConfig(tenant, ChannelEnum.DIDI.getName(), "", new DiDiConfig());
            if (diDiConfig != null) {
                Wrapper<DiDiUser> wrapper = new EntityWrapper<>();
                wrapper.eq(DiDiUser.TENANT, tenant);
                wrapper.eq(DiDiUser.PHONE, phone);
                List<DiDiUser> diDiUserList = didiUserMapper.selectList(wrapper);

                if (CollectionUtils.isEmpty(diDiUserList)) {
                    try {
                        UcUserDto ucUserDto = iUserCenterService.getCompleteUcUserDtoByPhone(phone, tenant);
                        DiDiUser diDiUser = DiDiUtil.convertToDiDiUser(tenant, ucUserDto);
                        addSingleUser(tenant, diDiUser);
                    } catch (Exception e) {
                        String msg = "滴滴企业版获取URL同步用户异常，异常信息：" + e.getMessage();
                        logger.error(msg);
                        MailSenderUtil.sendCommonMail(developerService.listEmailByType("KF"), "滴滴企业版用户同步异常", msg);
                    }
                } else {
                    // 用户如果离职则在滴滴中删除（正常的话还需要对比用户信息并更新变更的部分，但是现在用户只同步了手机号和姓名）
                    try {
                        DiDiUser diDiUser = diDiUserList.get(0);
                        UcUserDto ucUserDto = iUserCenterService.getCompleteUcUserDtoByPhone(phone, tenant);
                        if (ucUserDto.getValid() != 1 || ucUserDto.getDr() == 1) {
                            deleteUsers(tenant, Collections.singletonList(diDiUser));
                        }
                    } catch (Exception e) {
                        logger.error("获取滴滴企业版URL对离职人员删除用户异常，异常信息", e);
                        MailSenderUtil.sendCommonMail(developerService.listEmailByType("YY"), "滴滴用户删除", e.getMessage());
                    }
                }
            }
        }
        return didiH5Url;
    }

    /**
     * 获取需要同步的用户
     *
     * @param tenant   租户ID
     * @param userList 用户中心用户列表
     * @return <code>{"nameError":"","phoneError":"","data":""}</code>
     */
    private Map<String, Object> getNeedAsyDiDiUsers(String tenant, List<UcUserDto> userList) {
        Map<String, Object> result = new HashMap<>();

        Wrapper<DiDiUser> diDiUserWrapper = new EntityWrapper<>();
        diDiUserWrapper.eq(DiDiUser.TENANT, tenant);
        List<DiDiUser> hasSyncUserList = didiUserMapper.selectList(diDiUserWrapper);


        StringBuilder phoneError = new StringBuilder();
        StringBuilder nameError = new StringBuilder();

        List<DiDiUser> needSyncUsers = new ArrayList<>();


        if (!CollectionUtils.isEmpty(userList)) {
            for (UcUserDto anUserList : userList) {
                boolean add = true;
                if (hasSyncUserList != null && hasSyncUserList.size() > 0) {
                    for (DiDiUser hasSyncUser : hasSyncUserList) {
                        if (anUserList.getPhone().equals(hasSyncUser.getPhone())) {
                            add = false;
                            break;
                        }
                    }
                }
                if (add) {
                    if (!checkPhone(anUserList.getPhone())) {
                        phoneError.append(",").append(anUserList.getPhone());
                        continue;
                    }
                    if (!checkName(anUserList.getUserName())) {
                        nameError.append(",").append(anUserList.getUserName());
                        continue;
                    }
                    needSyncUsers.add(DiDiUtil.convertToDiDiUser(tenant, anUserList));
                }
            }
        }
        result.put("nameError", nameError.toString());
        result.put("phoneError", phoneError.toString());
        result.put("data", needSyncUsers);
        return result;
    }

    private Map<String, Object> getMemberData(DiDiConfig diDiConfig, List<DiDiUser> users) throws CustomException, JSONException {
        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put(DiDiConstants.KEY_CLIENT_ID, diDiConfig.getClientId());
        paramsMap.put(DiDiConstants.KEY_ACCESS_TOKEN, diDiRMIUtils.getToken(diDiConfig));
        paramsMap.put(DiDiConstants.KEY_TIMESTAMP, System.currentTimeMillis());
        paramsMap.put(DiDiConstants.KEY_COMPANY_ID, diDiConfig.getCompanyId());
        JSONArray memberArray = new JSONArray();
        for (DiDiUser user : users) {
            JSONObject memberDataMap = new JSONObject();
            String phone = user.getPhone() == null ? "" : user.getPhone();
            String name = user.getRealname() == null ? "" : user.getRealname();
            memberDataMap.put("phone", phone);
            memberDataMap.put("realname", name);
            memberArray.put(memberDataMap);
        }
        paramsMap.put(DiDiConstants.DATA, memberArray.toString());
        Map<String, Object> memberAddParamsMap = diDiRMIUtils.keySort(paramsMap, diDiConfig);
        String sign = diDiRMIUtils.concatRequestParamsAndMd5Encode(memberAddParamsMap);
        memberAddParamsMap.put(DiDiConstants.KEY_SIGN, sign);
        return memberAddParamsMap;
    }

    /**
     * 单个滴滴用户信息组装
     *
     * @param diDiConfig 企业配置信息
     * @param diDiUser   滴滴用户
     * @return
     */
    private Map<String, Object> getSingleMemberData(DiDiConfig diDiConfig, DiDiUser diDiUser) {
        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put(DiDiConstants.KEY_CLIENT_ID, diDiConfig.getClientId());
        paramsMap.put(DiDiConstants.KEY_ACCESS_TOKEN, diDiRMIUtils.getToken(diDiConfig));
        paramsMap.put(DiDiConstants.KEY_TIMESTAMP, System.currentTimeMillis());
        paramsMap.put(DiDiConstants.KEY_COMPANY_ID, diDiConfig.getCompanyId());

        JSONObject memberDataMap = new JSONObject();
        memberDataMap.put("phone", diDiUser.getPhone());
        memberDataMap.put("realname", diDiUser.getRealname());
        paramsMap.put(DiDiConstants.DATA, memberDataMap);

        paramsMap.put(DiDiConstants.DATA, memberDataMap.toString());
        Map<String, Object> memberAddParamsMap = diDiRMIUtils.keySort(paramsMap, diDiConfig);
        String sign = diDiRMIUtils.concatRequestParamsAndMd5Encode(memberAddParamsMap);
        memberAddParamsMap.put(DiDiConstants.KEY_SIGN, sign);
        return memberAddParamsMap;
    }

    /**
     * 组装用户修改信息
     *
     * @param diDiConfig 企业配置信息
     * @param diDiUser   滴滴用户列表
     * @return
     */
    private Map<String, Object> getUpdateMemberData(DiDiConfig diDiConfig, DiDiUser diDiUser) {
        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put(DiDiConstants.KEY_CLIENT_ID, diDiConfig.getClientId());
        paramsMap.put(DiDiConstants.KEY_ACCESS_TOKEN, diDiRMIUtils.getToken(diDiConfig));
        paramsMap.put(DiDiConstants.KEY_TIMESTAMP, System.currentTimeMillis());
        paramsMap.put(DiDiConstants.KEY_COMPANY_ID, diDiConfig.getCompanyId());
        paramsMap.put("member_id", diDiUser.getDdMemberId());

        JSONObject memberDataMap = new JSONObject();
        memberDataMap.put("phone", diDiUser.getPhone());
        memberDataMap.put("realname", diDiUser.getRealname());
        paramsMap.put(DiDiConstants.DATA, memberDataMap.toString());

        Map<String, Object> updateParamsMap = diDiRMIUtils.keySort(paramsMap, diDiConfig);
        String sign = diDiRMIUtils.concatRequestParamsAndMd5Encode(updateParamsMap);
        updateParamsMap.put(DiDiConstants.KEY_SIGN, sign);

        return updateParamsMap;
    }

    /**
     * 组装用户删除信息
     *
     * @param diDiConfig   企业配置信息
     * @param diDiUserList 滴滴用户列表
     * @return
     */
    private Map<String, Object> getDeleteMemberData(DiDiConfig diDiConfig, List<DiDiUser> diDiUserList) {
        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put(DiDiConstants.KEY_CLIENT_ID, diDiConfig.getClientId());
        paramsMap.put(DiDiConstants.KEY_ACCESS_TOKEN, diDiRMIUtils.getToken(diDiConfig));
        paramsMap.put(DiDiConstants.KEY_TIMESTAMP, System.currentTimeMillis());
        paramsMap.put(DiDiConstants.KEY_COMPANY_ID, diDiConfig.getCompanyId());

        //memberIds 员工在滴滴企业的ID(多个用_连接，如459554_45960，最多100个,该方法不控制，由远程调用的地方控制)
        StringBuilder memberIds = new StringBuilder();
        for (DiDiUser diDiUser : diDiUserList) {
            memberIds.append(diDiUser.getDdMemberId()).append("_");
        }
        paramsMap.put("member_id", memberIds.toString().substring(0, memberIds.length() - 1));

        Map<String, Object> deleteParamsMap = diDiRMIUtils.keySort(paramsMap, diDiConfig);
        String sign = diDiRMIUtils.concatRequestParamsAndMd5Encode(deleteParamsMap);
        deleteParamsMap.put(DiDiConstants.KEY_SIGN, sign);
        return deleteParamsMap;
    }

    private boolean checkPhone(String phone) {
        return !StringUtil.isEmpty(phone) && PHONE_PATTERN.matcher(phone).matches();
    }

    private boolean checkName(String name) {
        return !StringUtil.isEmpty(name) && (NAME_PATTERN1.matcher(name).matches() || NAME_PATTERN2.matcher(name).matches());
    }
}